﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAKS.Models;
using NHibernate;
using NHibernate.Criterion;


namespace SAKS.Services.Query
{
    class PagedPersonInfoSearch : PagedQueryOverBase<PersonInfo>
    {
        public PagedPersonInfoSearch(ISession session) : base(session) { }
        public string Key { get; set; }

        protected override IQueryOver<PersonInfo, PersonInfo> GetQuery()
        {
            var query = Session.QueryOver<PersonInfo>();
            if (!string.IsNullOrEmpty(Key))
            {
                query = query.WhereRestrictionOn(p => p.Name).IsLike(Key, MatchMode.Anywhere);
            }
            query = query.OrderBy(p => p.Name).Asc;
            return query;
        }
    }
}
